﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GtsServer.Model;
using GtsServer.Common;
using GtsServer.Manage.Controller;

namespace GtsServer.Manage.IISPage.Ajax
{
    /// <summary>
    /// PrizeConvertUserRecordAjax 的摘要说明
    /// </summary>
    public class PrizeConvertUserRecordAjax : IHttpHandler
    {
        PrizeConvertUserRecordController Controller = new PrizeConvertUserRecordController();
        public void ProcessRequest(HttpContext context)
        {
            string type = string.Empty;
            if (context.Request["action"] != null)
            {
                type = context.Request["action"];

                switch (type)
                {
                    case "GetList":
                        GetList(context);
                        break;
                    case "GetState":
                        GetState(context);
                        break;
                    default:
                        break;
                }
            }
        }
        private void GetList(HttpContext context)
        {
            int pageIndex = Convert.ToInt32(context.Request["pageIndex"]);
            int pageSize = Convert.ToInt32(context.Request["pageSize"]);
            int count = 0;
            string IMSI = context.Request["IMSI"] ?? "";
            string UserAccount = context.Request["UserAccount"] ?? "";
            string PrizeName = context.Request["PrizeName"] ?? "";
            string Stutas = context.Request["Stutas"]??"";
            List<PrizeConvertUserRecordModel> list = Controller.GetList(Stutas,IMSI, UserAccount, PrizeName, pageIndex, pageSize, out count);
            string json = JsonHelper.ListToJson<PrizeConvertUserRecordModel>(list, count.ToString());
            context.Response.Write(json);
        }
        private void GetState(HttpContext context)
        {
            List<PrizeConvertUserRecord> list = new List<PrizeConvertUserRecord>();
            foreach (var item in Enum.GetValues(typeof(EnumPrizeConvertUserRecord)))
            {
                PrizeConvertUserRecord model = new PrizeConvertUserRecord()
                {
                    name = item.ToString(),
                    value = Convert.ToInt32(item)
                };
                list.Add(model);
            }
            context.Response.Write(JsonHelper.ListToJson<PrizeConvertUserRecord>(list));
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}